<script type="text/javascript">
	<% if @traffic_strategy.promotion_info? %>
		var sResult = confirm("发生策略竞和,是否覆盖之前的策略，使当前策略启用，之前的策略将删除");
		if(sResult)
		{
			$.ajax({
			  type: '<%= request.method %>',
			  url: "<%= request.fullpath %>",
			  data: <%= raw params.merge(promotion_info: true).to_json %>
			});
		}
	<% end %>
</script>

<%= simple_form_for [:admin, @traffic_strategy], :defaults => { :input_html => { :class => "form-control" } }, remote: true, html: {class: 'form-horizontal' } do |f| %>
	<fieldset>
		<legend><%= title %></legend>
		<%= f.input :name, label: '策略名称'  %>
	  <%= f.association :terminal_group, label: '设备组', prompt: "其他设备"  %>
	  <%= f.association :account_group, label: '账号组', prompt: "其他账号"  %>
	  <div class="form-group integer required traffic_strategy_duration_total <%= "has-error" if @traffic_strategy.errors.messages[:duration_total] %>">
	  	<div class="integer required col-md-5 control-label">
		  	<%= f.label :duration_total, '总时长' %>
	  	</div>
		  <div class="col-md-3">
		  	<label class="checkbox-inline">
				  <input type="checkbox" class="checkbox style-0" id="duration_total_check" <%= "checked" if @traffic_strategy.duration_total == -1 %>>
				  <span>不限</span>
				</label>
		  </div>
		  <div class="col-md-4">
		  	<div id="duration_total_div" style="display:<%= "none" if @traffic_strategy.duration_total == -1 %>">
	  			<div class="input-group">
						<%= f.input_field :duration_total %>
						<span class="input-group-addon">分钟</span>
					</div>
		  	</div>

		  </div>
		  <div class="col-md-5"></div>
		  <div class="col-sm-7">
			  <% if @traffic_strategy.errors.messages[:duration_total].present? %>
	  			<span class="help-block"><%= @traffic_strategy.errors.messages[:duration_total].join("") %></span>
		  	<% end %>	  	
		  </div>
	  </div>
	  <div class="form-group integer required traffic_strategy_beaut_traffic_total <%= "has-error" if @traffic_strategy.errors.messages[:traffic_total] %>">
	  	<div class="integer required col-md-5 control-label">
		  	<%= f.label :beaut_traffic_total, '总流量' %>
	  	</div>
		  <div class="col-md-3">
		  	<label class="checkbox-inline">
				  <input type="checkbox" class="checkbox style-0" id="beaut_traffic_total_check" <%= "checked" if @traffic_strategy.beaut_traffic_total == -1 %>>
				  <span>不限</span>
				</label>
		  </div>
		  <div class="col-md-3">
		  	<div id="beaut_traffic_total_div" style="display:<%= "none" if @traffic_strategy.beaut_traffic_total == -1 %>">
		  		<div class="input-group">
			  		<%= f.input_field :beaut_traffic_total %>
			  		<span class="input-group-addon">M</span>
		  		</div>
		  	</div>
		  </div>
		  <div class="col-md-5"></div>
		  <div class="col-sm-7">
			  <% if @traffic_strategy.errors.messages[:traffic_total].present? %>
		  		<span class="help-block"><%= @traffic_strategy.errors.messages[:traffic_total].join("") %></span>
			  <% end %>		  	
		  </div>
	  </div>
	  <div class="form-group integer required traffic_strategy_limit_down <%= "has-error" if @traffic_strategy.errors.messages[:limit_down] %>">
	  	<div class="integer required col-md-5 control-label">
		  	<%= f.label :limit_down, '下行速度限制' %>
	  	</div>
			  <div class="col-md-3">
			  	<label class="checkbox-inline">
					  <input type="checkbox" class="checkbox style-0" id="limit_down_check" <%= "checked" if @traffic_strategy.limit_down == -1 %>>
					  <span>不限</span>
					</label>
			  </div>
			  <div class="col-md-4">
			  	<div id="limit_down_div" style="display:<%= "none" if @traffic_strategy.limit_down == -1 %>">
			  		<div class="input-group">
				  		<%= f.input_field :limit_down %>
			  			<span class="input-group-addon">KB/s</span>
			  		</div>
			  	</div>
			  </div>
  		  <div class="col-md-5"></div>
			  <div class="col-sm-7">
				  <% if @traffic_strategy.errors.messages[:limit_down].present? %>
			  		<span class="help-block"><%= @traffic_strategy.errors.messages[:limit_down].join("") %></span>
				  <% end %>
			  </div>
	  </div>
	  <div class="form-group integer required traffic_strategy_limit_up <%= "has-error" if @traffic_strategy.errors.messages[:limit_up] %>">
	  	<div class="integer required col-md-5 control-label">
		  	<%= f.label :limit_up, '上行速度限制' %>
	  	</div>
			  <div class="col-md-3">
			  	<label class="checkbox-inline">
					  <input type="checkbox" class="checkbox style-0" id="limit_up_check" <%= "checked" if @traffic_strategy.limit_up == -1 %>>
					  <span>不限</span>
					</label>
			  </div>
			  <div class="col-md-4">
			  	<div id="limit_up_div" style="display:<%= "none" if @traffic_strategy.limit_up == -1 %>">
			  		<div class="input-group">
				  		<%= f.input_field :limit_up %>
			  			<span class="input-group-addon">KB/s</span>
			  		</div>
			  	</div>
			  </div>
  		  <div class="col-md-5"></div>
			  <div class="col-sm-7">
				  <% if @traffic_strategy.errors.messages[:limit_up].present? %>
		  		<span class="help-block"><%= @traffic_strategy.errors.messages[:limit_up].join("") %></span>
			  	<% end %>
			  </div>
	  </div>
	  <%= f.input :times, label: '重复使用次数'  %>
	  <%= f.input :status, label: '启用', :input_html => { :class => "" }  %>
	  <%= f.button :wrapped, value: '提 交' %>
	</fieldset>
<% end %>

<script type="text/javascript">

	$(function() {
		$("input#duration_total_check").click(function() {
      if(this.checked){
        $('div#duration_total_div').hide();
        $('input#traffic_strategy_duration_total').val("-1")
      } else {
      	$('div#duration_total_div').show()
      	$('input#traffic_strategy_duration_total').val("0");
      }
    });

    $("input#beaut_traffic_total_check").click(function() {
      if(this.checked){
        $('div#beaut_traffic_total_div').hide()
        $('input#traffic_strategy_beaut_traffic_total').val("-1")
      } else {
      	$('div#beaut_traffic_total_div').show()
      	$('input#traffic_strategy_beaut_traffic_total').val("0");
      }
    });

    $("input#limit_down_check").click(function() {
      if(this.checked){
        $('div#limit_down_div').hide()
        $('input#traffic_strategy_limit_down').val("-1")
      } else {
      	$('div#limit_down_div').show()
      	$('input#traffic_strategy_limit_down').val("0");
      }
    });

    $("input#limit_up_check").click(function() {
      if(this.checked){
        $('div#limit_up_div').hide()
        $('input#traffic_strategy_limit_up').val("-1")
      } else {
      	$('div#limit_up_div').show()
      	$('input#traffic_strategy_limit_up').val("0")
      }
    });		
	})
    
</script>
<%= javascript_include_tag "prevent_label.js" %>